package com.hanamaki.homework;

import java.util.Scanner;

public class Demo04 {

    static Scanner scanner;
    static {
        scanner = new Scanner(System.in);
    }

    public static void main(String[] args) {

        yearMonth();
    }

    public static void yearMonth() {
        String answer = "是";
        while (answer.equals("是")) {
            System.out.println("请输入年份！");
            int year = scanner.nextInt();
            if (year <= 0) {
                System.out.println("您输入的年份有误!(年份必须大于0)");
                System.out.println("请重新输入正确的年份：");
                continue;
            }
            System.out.println("请输入月份！");
            int mon = scanner.nextInt();
            if (mon > 12 || mon < 1) {
                System.out.println("您输入的月份有误!(月份范围为1-12)");
                System.out.println("请重新输入正确的月份：");
                continue;
            }

            int day = 0;
            switch (mon) {
                case 2:
                    day = 28;
                    if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
                        day++;
                    }
                    break;
                case 4:
                case 6:
                case 9:
                case 11:
                    day = 30;
                    break;
                default:
                    day = 31;
            }
            System.out.println(year + "年" + mon + "月一共有" + day + "天");
            System.out.println("是否要再次查询？");
            answer = scanner.next();
        }
        System.out.println("感谢您的使用！");
    }
}
